package com.example.tliasmanagement.controller;

import com.example.tliasmanagement.dto.DemoDto;
import lombok.Data;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoController {
    // http://localhost:8080/demo?username=zhangsan&password=123456&createTime=2024-04-01 10:00:00
    @GetMapping("/demo")
    public String demo(DemoDto demoDto){
        return demoDto.getUsername() + "," + demoDto.getPassword();
    }
    // http://localhost:8080/demo
    // {username:zhangsan , password:123456}
    @PostMapping("/demo")
    public DemoDto postDemo(@RequestBody DemoDto demoDto){
        return demoDto;
    }

    @PostMapping("param")
    public String param(String username, String password){
        return username + ":" + password;
    }
    @GetMapping("param")
    public String getParam(String username, String password){
        return username + ":" + password;
    }

    @Data
    public static class User{
        private String username;
        private String password;
    }

    @GetMapping("param2")
    public String getParam2(User user){
        return user.getUsername() + ":" + user.getPassword();
    }

    @GetMapping("/err")
    public String err(){
        int i = 1/0;
        return "ok";
    }

}
